
package com.cashbox.gui.inventario;

import com.cashbox.dao.conexiones.ConexionFactory;
import com.cashbox.dao.inventario.DaoInventarioHb;
import com.cashbox.exepciones.CapaDatosExcepcion;
import com.cashbox.gui.actions.EliminarAction;
import com.cashbox.gui.actions.GuardarAction;
import com.cashbox.gui.actions.NuevoAction;
import com.cashbox.gui.actions.RefrescarAction;
import com.cashbox.gui.componentes.CashBoxPanel;
import com.cashbox.modelos.inventario.Marca;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Gustavo Enrique Ruiz Cisneros
 */
public class Inventario extends CashBoxPanel {

    private NuevaMarca nuevo = new NuevaMarca();
    private RefrescarMarca refresh = new RefrescarMarca();
    private EliminarMarca eliminar = new EliminarMarca();
    private GuardarMarca guardar = new GuardarMarca();
    
    private EntityManager em;
    private List<Marca> marcasLista = new ArrayList<Marca>();

    public Inventario() {
        initComponents();
        em = ConexionFactory.getInstance().getEntitiManager();
        init();
    }

    public List<Marca> getMarcasLista() {
        return marcasLista;
    }

    public void setMarcasLista(List<Marca> marcasLista) {
        this.marcasLista = marcasLista;
    }

    private void init() {
        btnNuevo.setAction(nuevo);
        btnRefrescar.setAction(refresh);
        btnEliminar.setAction(eliminar);
        btnGuardar.setAction(guardar);

    }

    public class NuevaMarca extends NuevoAction {

        public NuevaMarca() {
            super();
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
        }
    }

    public class GuardarMarca extends GuardarAction {

        public GuardarMarca() {
            super();
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
        }
    }

    public class RefrescarMarca extends RefrescarAction {

        public RefrescarMarca() {
            super();
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
        }
    }

    public class EliminarMarca extends EliminarAction {

        public EliminarMarca() {
            super();
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cashBoxPanel1 = new com.cashbox.gui.componentes.CashBoxPanel();
        btnGuardar = new com.cashbox.gui.componentes.CashBoxButton();
        btnEliminar = new com.cashbox.gui.componentes.CashBoxButton();
        btnRefrescar = new com.cashbox.gui.componentes.CashBoxButton();
        btnNuevo = new com.cashbox.gui.componentes.CashBoxButton();
        txtIdMarca = new com.cashbox.gui.componentes.CashBoxTextField();
        lblIdMarca = new com.cashbox.gui.componentes.CashBoxLabel();
        lblClave = new com.cashbox.gui.componentes.CashBoxLabel();
        txtDescripcion = new com.cashbox.gui.componentes.CashBoxLabel();
        cashBoxTextField1 = new com.cashbox.gui.componentes.CashBoxTextField();
        cashBoxTextField2 = new com.cashbox.gui.componentes.CashBoxTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblMarcas = new com.cashbox.gui.componentes.CashBoxTable();
        lblTitulo = new com.cashbox.gui.componentes.CashBoxLabel();
        jSeparator1 = new javax.swing.JSeparator();

        btnGuardar.setText("cashBoxButton1");

        btnEliminar.setText("cashBoxButton2");

        btnRefrescar.setText("cashBoxButton3");

        btnNuevo.setText("cashBoxButton4");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblMarcas, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.id}"), txtIdMarca, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        lblIdMarca.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblIdMarca.setText("Id:");

        lblClave.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblClave.setText("Clave:");

        txtDescripcion.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        txtDescripcion.setText("Descripción:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblMarcas, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.clave}"), cashBoxTextField1, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblMarcas, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.descripcion}"), cashBoxTextField2, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        tblMarcas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${marcasLista}");
        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, tblMarcas, "");
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Long.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${clave}"));
        columnBinding.setColumnName("Clave");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descripcion}"));
        columnBinding.setColumnName("Descripcion");
        columnBinding.setColumnClass(String.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(tblMarcas);

        lblTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblTitulo.setText("Marcas");
        lblTitulo.setFont(new java.awt.Font("Calibri", 0, 40)); // NOI18N
        lblTitulo.setTamFuente(34);

        jSeparator1.setForeground(new java.awt.Color(102, 102, 102));

        org.jdesktop.layout.GroupLayout cashBoxPanel1Layout = new org.jdesktop.layout.GroupLayout(cashBoxPanel1);
        cashBoxPanel1.setLayout(cashBoxPanel1Layout);
        cashBoxPanel1Layout.setHorizontalGroup(
            cashBoxPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(cashBoxPanel1Layout.createSequentialGroup()
                .add(7, 7, 7)
                .add(cashBoxPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(cashBoxPanel1Layout.createSequentialGroup()
                        .add(btnNuevo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(3, 3, 3)
                        .add(btnRefrescar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(3, 3, 3)
                        .add(btnEliminar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(3, 3, 3)
                        .add(btnGuardar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(0, 133, Short.MAX_VALUE))
                    .add(cashBoxPanel1Layout.createSequentialGroup()
                        .add(cashBoxPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(lblIdMarca, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(txtDescripcion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(5, 5, 5)
                        .add(cashBoxPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(cashBoxPanel1Layout.createSequentialGroup()
                                .add(txtIdMarca, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(5, 5, 5)
                                .add(lblClave, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(5, 5, 5)
                                .add(cashBoxTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 302, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(cashBoxTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .add(cashBoxPanel1Layout.createSequentialGroup()
                        .add(jScrollPane1)
                        .add(7, 7, 7))))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, lblTitulo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jSeparator1)
        );
        cashBoxPanel1Layout.setVerticalGroup(
            cashBoxPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, cashBoxPanel1Layout.createSequentialGroup()
                .add(5, 5, 5)
                .add(lblTitulo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(5, 5, 5)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cashBoxPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtIdMarca, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblIdMarca, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblClave, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(cashBoxTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(5, 5, 5)
                .add(cashBoxPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtDescripcion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(cashBoxTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(10, 10, 10)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(3, 3, 3)
                .add(cashBoxPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btnGuardar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnEliminar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnRefrescar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnNuevo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(5, 5, 5))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(cashBoxPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(cashBoxPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.cashbox.gui.componentes.CashBoxButton btnEliminar;
    private com.cashbox.gui.componentes.CashBoxButton btnGuardar;
    private com.cashbox.gui.componentes.CashBoxButton btnNuevo;
    private com.cashbox.gui.componentes.CashBoxButton btnRefrescar;
    private com.cashbox.gui.componentes.CashBoxPanel cashBoxPanel1;
    private com.cashbox.gui.componentes.CashBoxTextField cashBoxTextField1;
    private com.cashbox.gui.componentes.CashBoxTextField cashBoxTextField2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private com.cashbox.gui.componentes.CashBoxLabel lblClave;
    private com.cashbox.gui.componentes.CashBoxLabel lblIdMarca;
    private com.cashbox.gui.componentes.CashBoxLabel lblTitulo;
    private com.cashbox.gui.componentes.CashBoxTable tblMarcas;
    private com.cashbox.gui.componentes.CashBoxLabel txtDescripcion;
    private com.cashbox.gui.componentes.CashBoxTextField txtIdMarca;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
